package com.yls.except.service.impl;

import com.yls.except.dao.BaseDao;
import com.yls.except.task.RedisCash;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/20.
 */
@Service
@Repository(value = "baseService")
public class BaseServiceImpl {
    @Resource(name = "baseDao")
    private BaseDao baseDao;
    /**
     * 移除token
     *
     * @param uid 用户id
     */
    public static void removeUserTokenByUid(String uid) {
        List<String> list = RedisCash.getList("exceptuserToken");
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                String token = list.get(i);
                Map<String, String> tokenMap = RedisCash.getMap(token);
                String tokenuid = tokenMap.get("uid") + "";
                if (tokenuid.equals(uid)) {
                    RedisCash.removeListKey("exceptuserToken", token);
                    RedisCash.removeKey(token);
                }
            }
        }
    }
}
